package yc.day0110;

import yc.day0109.travelt.dao.TourRouteDao;
import yc.day0109.travelt.dao.impl.TourRouteDaoImpl;
import yc.day0109.travelt.po.TourRoute;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TraveltServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置中文字符乱码，解决request/reponse响应
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        TourRouteDao tourRouteDao = new TourRouteDaoImpl();
        Map<String,Object> map = new HashMap<>();
        String searchName = request.getAttribute("searchName") == null ? "" :
                String.valueOf(request.getAttribute("searchName"));
        if (!"".equals(searchName)) {
            map.put("trname", searchName);
        }
        List<TourRoute> tourRouteList = tourRouteDao.queryTourRoute(map);
        request.getRequestDispatcher("jsp//yc//day0110//travel-services.jsp").forward(request, response);
    }
}
